/*
 * Stock Results of all analyses
 * And permit to plot them cells by cells
 */
package IoTools;

import java.util.ArrayList;
import org.jfree.data.xy.XYZDataset;

/**
 *
 * @author godjam
 */
public class AnalyserCellByCell {

    ArrayList ResultList;

    /**
     *
     */
    public AnalyserCellByCell() {
        // this ArrayList will stock all results
        ResultList = new ArrayList();
    }

    /**
     * Permit to add a [result of cell spiking within a (Gamma/Delta) couple] into the
     * ArrayList 'ResultList'
     * @param result : an SimResult
     */
    public void Add(SimResult result) {
        ResultList.add(result);
    }

    public void PlotEmAll(String root, ParamSet p) {
        Integer gammaLoop = p.GammaLoop();
        Integer deltaLoop = p.DeltaLoop();        
        
///*
        // for N1
        double[] xvaluesN1 = new double[gammaLoop * deltaLoop];
        double[] yvaluesN1 = new double[gammaLoop * deltaLoop];
        double[] zvaluesN1 = new double[gammaLoop * deltaLoop];
        // for N2
        double[] xvaluesN2 = new double[gammaLoop * deltaLoop];
        double[] yvaluesN2 = new double[gammaLoop * deltaLoop];
        double[] zvaluesN2 = new double[gammaLoop * deltaLoop];
        // for N3
        double[] xvaluesN3 = new double[gammaLoop * deltaLoop];
        double[] yvaluesN3 = new double[gammaLoop * deltaLoop];
        double[] zvaluesN3 = new double[gammaLoop * deltaLoop];
        // for N4
        double[] xvaluesN4 = new double[gammaLoop * deltaLoop];
        double[] yvaluesN4 = new double[gammaLoop * deltaLoop];
        double[] zvaluesN4 = new double[gammaLoop * deltaLoop];
        // for AS
        double[] xvaluesAS = new double[gammaLoop * deltaLoop];
        double[] yvaluesAS = new double[gammaLoop * deltaLoop];
        double[] zvaluesAS = new double[gammaLoop * deltaLoop];

        // datas
        double[][] dataN1 = new double[][]{xvaluesN1, yvaluesN1, zvaluesN1};
        double[][] dataN2 = new double[][]{xvaluesN2, yvaluesN2, zvaluesN2};
        double[][] dataN3 = new double[][]{xvaluesN3, yvaluesN3, zvaluesN3};
        double[][] dataN4 = new double[][]{xvaluesN4, yvaluesN4, zvaluesN4};
        double[][] dataAS = new double[][]{xvaluesAS, yvaluesAS, zvaluesAS};

        // datas builder
        int r = 0;
        int c = 0;
        for (int i = 0; i < ResultList.size(); i++) {
            SimResult tempResult = (SimResult) ResultList.get(i);
            // up the row
            r++;
            // for N1
            setValue(dataN1, gammaLoop, c, r, tempResult.N1Spikes().size());
            setValue(dataN2, gammaLoop, c, r, tempResult.N2Spikes().size());
            setValue(dataN3, gammaLoop, c, r, tempResult.N3Spikes().size());
            setValue(dataN4, gammaLoop, c, r, tempResult.N4Spikes().size());
            setValue(dataAS, gammaLoop, c, r, tempResult.AstroSpikes().size());
            // up the column
            if (r == deltaLoop) {
                r = 0;
                c++;
            }
        }
        // Dataset creation
        XYZDataset xyzsetN1 = new XYZArrayDataset(dataN1);
        XYZDataset xyzsetN2 = new XYZArrayDataset(dataN2);
        XYZDataset xyzsetN3 = new XYZArrayDataset(dataN3);
        XYZDataset xyzsetN4 = new XYZArrayDataset(dataN4);
        XYZDataset xyzsetAS = new XYZArrayDataset(dataAS);

        // plot and export
        AnalyserTools.JFCXYBlockBuilder(root, "N1", "Behavior according to Gamma/Delta", "Gamma values", "Delta Values", xyzsetN1, p);
        AnalyserTools.JFCXYBlockBuilder(root, "N2", "Behavior according to Gamma/Delta", "Gamma values", "Delta Values", xyzsetN2, p);
        AnalyserTools.JFCXYBlockBuilder(root, "N3", "Behavior according to Gamma/Delta", "Gamma values", "Delta Values", xyzsetN3, p);
        AnalyserTools.JFCXYBlockBuilder(root, "N4", "Behavior according to Gamma/Delta", "Gamma values", "Delta Values", xyzsetN4, p);
        AnalyserTools.JFCXYBlockBuilder(root, "AS", "Behavior according to Gamma/Delta", "Gamma values", "Delta Values", xyzsetAS, p);
//*/
    }

    private static void setValue(double[][] dataXX, int GammaLoop,
            int c, int r, double value) {

        dataXX[0][(r - 1) * GammaLoop + c] = c;
        dataXX[1][(r - 1) * GammaLoop + c] = r;
        dataXX[2][(r - 1) * GammaLoop + c] = value;
        //System.out.println(value);
        
    }
}
